
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>序列协议 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="映射协议" href="mapping.html" />
    <link rel="prev" title="数字协议" href="number.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/c-api/sequence.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="mapping.html" title="映射协议"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="number.html" title="数字协议"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API 参考手册</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="abstract.html" accesskey="U">抽象对象层</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="sequence-protocol">
<span id="sequence"></span><h1>序列协议<a class="headerlink" href="#sequence-protocol" title="永久链接至标题">¶</a></h1>
<dl class="function">
<dt id="c.PySequence_Check">
int <code class="sig-name descname">PySequence_Check</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Check" title="永久链接至目标">¶</a></dt>
<dd><p>如果对象提供序列协议，函数返回 <code class="docutils literal notranslate"><span class="pre">1</span></code>，否则返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>。 请注意它将为具有 <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a> 方法的 Python 类返回 <code class="docutils literal notranslate"><span class="pre">1</span></code>，除非它们是 <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> 的子类，因为在一般情况下无法确定它所支持键类型。 此函数总是会成功执行。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Size">
Py_ssize_t <code class="sig-name descname">PySequence_Size</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Size" title="永久链接至目标">¶</a></dt>
<dt id="c.PySequence_Length">
Py_ssize_t <code class="sig-name descname">PySequence_Length</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Length" title="永久链接至目标">¶</a></dt>
<dd><p id="index-0">成功时返回序列中*o*的对象数,失败时返回``-1``. 相当于Python的``len(o)``表达式.</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Concat">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_Concat</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Concat" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>成功时返回 <em>o1</em> 和 <em>o2</em> 的拼接，失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 这等价于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">+</span> <span class="pre">o2</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Repeat">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_Repeat</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, Py_ssize_t<em> count</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Repeat" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>返回序列对象 <em>o</em> 重复 <em>count</em> 次的结果，失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 这等价于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">o</span> <span class="pre">*</span> <span class="pre">count</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_InPlaceConcat">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_InPlaceConcat</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o1</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_InPlaceConcat" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>成功时返回 <em>o1</em> 和 <em>o2</em> 的拼接，失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 在 <em>o1</em> 支持的情况下操作将 <em>原地</em> 完成。 这等价于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">o1</span> <span class="pre">+=</span> <span class="pre">o2</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_InPlaceRepeat">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_InPlaceRepeat</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, Py_ssize_t<em> count</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_InPlaceRepeat" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>Return the result of repeating sequence object返回序列对象 <em>o</em> 重复 <em>count</em> 次的结果，失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 在 <em>o</em> 支持的情况下该操作会 <em>原地</em> 完成。 这等价于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">o</span> <span class="pre">*=</span> <span class="pre">count</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_GetItem">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_GetItem</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, Py_ssize_t<em> i</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_GetItem" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>返回 <em>o</em> 中的第 <em>i</em> 号元素，失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 这等价于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">o[i]</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_GetSlice">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_GetSlice</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, Py_ssize_t<em> i1</em>, Py_ssize_t<em> i2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_GetSlice" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>返回序列对象 <em>o</em> 的 <em>i1</em> 到 <em>i2</em> 的切片，失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 这等价于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">o[i1:i2]</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_SetItem">
int <code class="sig-name descname">PySequence_SetItem</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, Py_ssize_t<em> i</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_SetItem" title="永久链接至目标">¶</a></dt>
<dd><p>将对象 <em>v</em> 赋值给 <em>o</em> 的第 <em>i</em> 号元素。 失败时会引发异常并返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>；成功时返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>。 这相当于 Python 语句 <code class="docutils literal notranslate"><span class="pre">o[i]</span> <span class="pre">=</span> <span class="pre">v</span></code>。 此函数 <em>不会</em> 改变对 <em>v</em> 的引用。</p>
<p>如果 <em>v</em> 为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>，元素将被删除，但是此特性已被弃用，应当改用 <a class="reference internal" href="#c.PySequence_DelItem" title="PySequence_DelItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySequence_DelItem()</span></code></a>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_DelItem">
int <code class="sig-name descname">PySequence_DelItem</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, Py_ssize_t<em> i</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_DelItem" title="永久链接至目标">¶</a></dt>
<dd><p>删除对象 <em>o</em> 的第 <em>i</em> 号元素。 失败时返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>。 这相当于 Python 语句 <code class="docutils literal notranslate"><span class="pre">del</span> <span class="pre">o[i]</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_SetSlice">
int <code class="sig-name descname">PySequence_SetSlice</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, Py_ssize_t<em> i1</em>, Py_ssize_t<em> i2</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *v</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_SetSlice" title="永久链接至目标">¶</a></dt>
<dd><p>将序列对象 <em>v</em> 赋值给序列对象 <em>o</em> 的从 <em>i1</em> 到 <em>i2</em> 切片。 这相当于 Python 语句 <code class="docutils literal notranslate"><span class="pre">o[i1:i2]</span> <span class="pre">=</span> <span class="pre">v</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_DelSlice">
int <code class="sig-name descname">PySequence_DelSlice</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, Py_ssize_t<em> i1</em>, Py_ssize_t<em> i2</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_DelSlice" title="永久链接至目标">¶</a></dt>
<dd><p>删除序列对象 <em>o</em> 的从 <em>i1</em> 到 <em>i2</em> 的切片。 失败时返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>。 这相当于 Python 语句 <code class="docutils literal notranslate"><span class="pre">del</span> <span class="pre">o[i1:i2]</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Count">
Py_ssize_t <code class="sig-name descname">PySequence_Count</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *value</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Count" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>value</em> 在 <em>o</em> 中出现的次数，即返回使得 <code class="docutils literal notranslate"><span class="pre">o[key]</span> <span class="pre">==</span> <span class="pre">value</span></code> 的键的数量。 失败时返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>。 这相当于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">o.count(value)</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Contains">
int <code class="sig-name descname">PySequence_Contains</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *value</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Contains" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>o</em> 是否包含 <em>value</em>。 如果 <em>o</em> 中的某一项等于 <em>value</em>，则返回 <code class="docutils literal notranslate"><span class="pre">1</span></code>，否则返回 <code class="docutils literal notranslate"><span class="pre">0</span></code>。 出错时，返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>。 这相当于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">value</span> <span class="pre">in</span> <span class="pre">o</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Index">
Py_ssize_t <code class="sig-name descname">PySequence_Index</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, <a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *value</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Index" title="永久链接至目标">¶</a></dt>
<dd><p>返回第一个索引*i*,其中 <code class="docutils literal notranslate"><span class="pre">o[i]</span> <span class="pre">==</span> <span class="pre">value</span></code>.出错时,返回 <code class="docutils literal notranslate"><span class="pre">-1</span></code>.相当于Python的``o.index(value)``表达式.</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_List">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_List</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_List" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>返回一个列表对象，其内容与序列或可迭代对象 <em>o</em> 相同，失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 返回的列表保证是一个新对象。 这等价于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">list(o)</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Tuple">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_Tuple</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Tuple" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p id="index-1">返回一个元组对象，其内容与序列或可迭代对象 <em>o</em> 相同，失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 如果 <em>o</em> 为元组，则将返回一个新的引用，在其他情况下将使用适当的内容构造一个元组。 这等价于 Python 表达式 <code class="docutils literal notranslate"><span class="pre">tuple(o)</span></code>。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Fast">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_Fast</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, const char<em> *m</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Fast" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>将序列或可迭代对象 <em>o</em> 作为其他 <code class="docutils literal notranslate"><span class="pre">PySequence_Fast*</span></code> 函数族可用的对象返回。 如果该对象不是序列或可迭代对象，则会引发 <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> 并将 <em>m</em> 作为消息文本。 失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。</p>
<p><code class="docutils literal notranslate"><span class="pre">PySequence_Fast*</span></code> 函数之所以这样命名，是因为它们会假定 <em>o</em> 是一个 <a class="reference internal" href="tuple.html#c.PyTupleObject" title="PyTupleObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyTupleObject</span></code></a> 或 <a class="reference internal" href="list.html#c.PyListObject" title="PyListObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyListObject</span></code></a> 并直接访问 <em>o</em> 的数据字段。</p>
<p>作为 CPython 的实现细节，如果 <em>o</em> 已经是一个序列或列表，它将被直接返回。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Fast_GET_SIZE">
Py_ssize_t <code class="sig-name descname">PySequence_Fast_GET_SIZE</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Fast_GET_SIZE" title="永久链接至目标">¶</a></dt>
<dd><p>在 <em>o</em> 由 <a class="reference internal" href="#c.PySequence_Fast" title="PySequence_Fast"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySequence_Fast()</span></code></a> 返回且 <em>o</em> 不为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> 的情况下返回 <em>o</em> 的长度。 也可以通过在 <em>o</em> 上调用 <a class="reference internal" href="#c.PySequence_Size" title="PySequence_Size"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySequence_Size()</span></code></a> 来获取大小，但是 <a class="reference internal" href="#c.PySequence_Fast_GET_SIZE" title="PySequence_Fast_GET_SIZE"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySequence_Fast_GET_SIZE()</span></code></a> 速度更快，因为它可以假定 <em>o</em> 为列表或元组。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Fast_GET_ITEM">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_Fast_GET_ITEM</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, Py_ssize_t<em> i</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Fast_GET_ITEM" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: Borrowed reference.</em><p>在 <em>o</em> 由 <a class="reference internal" href="#c.PySequence_Fast" title="PySequence_Fast"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySequence_Fast()</span></code></a> 返回且 <em>o</em> 不 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>，并且 <em>i</em> d在索引范围内的情况下返回 <em>o</em> 的第 <em>i</em> 号元素。</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_Fast_ITEMS">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>** <code class="sig-name descname">PySequence_Fast_ITEMS</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_Fast_ITEMS" title="永久链接至目标">¶</a></dt>
<dd><p>返回 PyObject 指针的底层数组。 假设 <em>o</em> 由 <a class="reference internal" href="#c.PySequence_Fast" title="PySequence_Fast"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySequence_Fast()</span></code></a> 返回且 <em>o</em> 不为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。</p>
<p>请注意,如果列表调整大小,重新分配可能会重新定位items数组.因此,仅在序列无法更改的上下文中使用基础数组指针.</p>
</dd></dl>

<dl class="function">
<dt id="c.PySequence_ITEM">
<a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a>* <code class="sig-name descname">PySequence_ITEM</code><span class="sig-paren">(</span><a class="reference internal" href="structures.html#c.PyObject" title="PyObject">PyObject</a><em> *o</em>, Py_ssize_t<em> i</em><span class="sig-paren">)</span><a class="headerlink" href="#c.PySequence_ITEM" title="永久链接至目标">¶</a></dt>
<dd><em class="refcount">Return value: New reference.</em><p>返回 <em>o</em> 的第 <em>i</em> 个元素或在失败时返回 <code class="docutils literal notranslate"><span class="pre">NULL</span></code>。 此形式比 <a class="reference internal" href="#c.PySequence_GetItem" title="PySequence_GetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySequence_GetItem()</span></code></a> 理馔，但不会检查 <em>o</em> 上的 <a class="reference internal" href="#c.PySequence_Check" title="PySequence_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySequence_Check()</span></code></a> 是否为真值，也不会对负序号进行调整。</p>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>上一个主题</h4>
  <p class="topless"><a href="number.html"
                        title="上一章">数字协议</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="mapping.html"
                        title="下一章">映射协议</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/c-api/sequence.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="mapping.html" title="映射协议"
             >下一页</a> |</li>
        <li class="right" >
          <a href="number.html" title="数字协议"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python/C API 参考手册</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="abstract.html" >抽象对象层</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>